<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="店铺管理">
<style>
    .pull-right {
        margin-top: 3px;
        margin-right: 5px;
    }

    #title {
        margin-top: 5px;
        margin-left: -10px;
    }
</style>
<!--suppress ALL -->
<form id="searchForm" class="form-panel" action="${basepath}/rest/manage/store/loadStoreData">
    <ul class="panel-content">
        <li>
            <div class="control-group span5">
                <div class="search-controls  controls">
                    <input type="text" name="storeName" id="title" value="" placeholder="搜索店铺名称、等级">
                </div>
            </div>
            <div class="form-actions span2">
                <button type="submit" class="button  button-primary">
                    搜索
                </button>
            </div>
            <div class="form-actions span2 pull-right">
                <a href="${basepath}/rest/manage/store/toStoreDetail" class="button button-success pull-right">
                    我的店铺信息
                </a>
            </div>
        </li>
    </ul>
</form>
<div id="grid"></div>
<script>
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '序号', dataIndex: 'id', elCls: 'center', width: '5%'},
                {title: '用户名称', dataIndex: 'nickname', elCls: 'center', width: '25%'},
                {title: '用户等级', dataIndex: 'rankName', elCls: 'center', width: '15%'},
                {title: '总销量金额', dataIndex: 'walletMoney', elCls: 'center', width: '15%'},
                {title: '获得积分', dataIndex: 'score', elCls: 'center', width: '15%'},
                {
                    title: '分销订单', dataIndex: 'id', elCls: 'center', width: '15%', renderer: function (value, data) {
                    return '<a href="${basepath}/rest/manage/order/toStoreOrder?id=' + value + '">查看</a>';
                }
                }
            ];

    var store = new Store({
                url: '/rest/manage/user/selectStoreList',
                autoLoad: true, //自动加载数据
                params: { //配置初始请求的参数
                    length: '10'
                },
                pageSize: 10,	// 配置分页数目
                root: 'data',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                width: '100%',
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });
    grid.render();

    //搜索框表单
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    //改变店铺状态
    function changeStatus(id, status) {
        $.ajax({
            type: 'POST',
            url: '${basepath}/rest/manage/store/updateStatus',
            dataType: 'json',
            data: {
                id: id,
                status: status
            },
            success: function () {
                var obj = form.serializeToObject();
                obj.start = 0; //返回第一页
                store.load(obj);
            }
        })
    }
</script>

</@page.pageBase>
